<?php
/*
 * Author:  Somnath Shinde- soma.shinde@gmail.com Mobile No:- 9423792564
 * 
 * Create Date: 
 * 
 * Version of MYSQL_to_PHP: 1.1
 * 
 * Ranzani( YZ'S );
 * 
 */
require_once 'Base/BaseUrines.class.php';

Class Urines {

	public function  __construct() {
			if( true == isset( $_SERVER['connection'] ) ) {
				$this->connection = $_SERVER['connection'];
			}
	}

	
	/*******************************************************************************************
	******************************** Fetch Functions *******************************************
	*******************************************************************************************/

	public function fetchSql( $strSql ) {
		$result = $this->connection->RunQuery( $strSql );
		$arrobjUrines = array();
		while( $row = $result->fetch_array( MYSQLI_ASSOC ) ) {
			$objUrines = new BaseUrines();
			$objUrines->setId( ( true == isset( $row["id"] ) ) ? $row["id"] : 'NULL' );
			$objUrines->setPatientId( ( true == isset( $row["patient_id"] ) ) ? $row["patient_id"] : 'NULL' );
			$objUrines->setCasePaperId( ( true == isset( $row["case_paper_id"] ) ) ? $row["case_paper_id"] : 'NULL' );
			$objUrines->setDoctorId( ( true == isset( $row["doctor_id"] ) ) ? $row["doctor_id"] : 'NULL' );
			$objUrines->setDepartmentId( ( true == isset( $row["department_id"] ) ) ? $row["department_id"] : 'NULL' );
			$objUrines->setDiagnosisId( ( true == isset( $row["diagnosis_id"] ) ) ? $row["diagnosis_id"] : 'NULL' );
			$objUrines->setChargeId( ( true == isset( $row["charge_id"] ) ) ? $row["charge_id"] : 'NULL' );
			$objUrines->setColor( ( true == isset( $row["color"] ) ) ? $row["color"] : 'NULL' );
			$objUrines->setDeposit( ( true == isset( $row["deposit"] ) ) ? $row["deposit"] : 'NULL' );
			$objUrines->setReaction( ( true == isset( $row["reaction"] ) ) ? $row["reaction"] : 'NULL' );
			$objUrines->setAlbumin( ( true == isset( $row["albumin"] ) ) ? $row["albumin"] : 'NULL' );
			$objUrines->setSugar( ( true == isset( $row["sugar"] ) ) ? $row["sugar"] : 'NULL' );
			$objUrines->setScetene( ( true == isset( $row["scetene"] ) ) ? $row["scetene"] : 'NULL' );
			$objUrines->setDiaceticAcid( ( true == isset( $row["diacetic_acid"] ) ) ? $row["diacetic_acid"] : 'NULL' );
			$objUrines->setBileSacts( ( true == isset( $row["bile_sacts"] ) ) ? $row["bile_sacts"] : 'NULL' );
			$objUrines->setBileDigments( ( true == isset( $row["Bile_digments"] ) ) ? $row["Bile_digments"] : 'NULL' );
			$objUrines->setPusCells( ( true == isset( $row["pus_cells"] ) ) ? $row["pus_cells"] : 'NULL' );
			$objUrines->setPbc( ( true == isset( $row["pbc"] ) ) ? $row["pbc"] : 'NULL' );
			$objUrines->setCasts( ( true == isset( $row["casts"] ) ) ? $row["casts"] : 'NULL' );
			$objUrines->setCrystals( ( true == isset( $row["crystals"] ) ) ? $row["crystals"] : 'NULL' );
			$objUrines->setCells( ( true == isset( $row["cells"] ) ) ? $row["cells"] : 'NULL' );
			$objUrines->setMicroOrganisms( ( true == isset( $row["micro_organisms"] ) ) ? $row["micro_organisms"] : 'NULL' );
			$objUrines->setRemarks( ( true == isset( $row["remarks"] ) ) ? $row["remarks"] : 'NULL' );
			$objUrines->setDocumentAttachmentId( ( true == isset( $row["document_attachment_id"] ) ) ? $row["document_attachment_id"] : 'NULL' );
			$objUrines->setAttachmentPath( ( true == isset( $row["attachment_path"] ) ) ? $row["attachment_path"] : 'NULL' );
			$objUrines->setCreatedOn( ( true == isset( $row["created_on"] ) ) ? $row["created_on"] : 'NULL' );
			$objUrines->setCreatedBy( ( true == isset( $row["created_by"] ) ) ? $row["created_by"] : 'NULL' );
			$objUrines->setUpdatedOn( ( true == isset( $row["updated_on"] ) ) ? $row["updated_on"] : 'NULL' );
			$objUrines->setUpdatedBy( ( true == isset( $row["updated_by"] ) ) ? $row["updated_by"] : 'NULL' );
			array_push( $arrobjUrines, $objUrines );
		}
		return $arrobjUrines;
	}
	public function fetchAllUrines() {
		$result = $this->connection->RunQuery("SELECT * FROM URINES");
		$arrobjUrines = array();
		while( $row = $result->fetch_array( MYSQLI_ASSOC ) ) {
			$objUrines = new BaseUrines();
			$objUrines->setId( ( true == isset( $row["id"] ) ) ? $row["id"] : 'NULL' );
			$objUrines->setPatientId( ( true == isset( $row["patient_id"] ) ) ? $row["patient_id"] : 'NULL' );
			$objUrines->setCasePaperId( ( true == isset( $row["case_paper_id"] ) ) ? $row["case_paper_id"] : 'NULL' );
			$objUrines->setDoctorId( ( true == isset( $row["doctor_id"] ) ) ? $row["doctor_id"] : 'NULL' );
			$objUrines->setDepartmentId( ( true == isset( $row["department_id"] ) ) ? $row["department_id"] : 'NULL' );
			$objUrines->setDiagnosisId( ( true == isset( $row["diagnosis_id"] ) ) ? $row["diagnosis_id"] : 'NULL' );
			$objUrines->setChargeId( ( true == isset( $row["charge_id"] ) ) ? $row["charge_id"] : 'NULL' );
			$objUrines->setColor( ( true == isset( $row["color"] ) ) ? $row["color"] : 'NULL' );
			$objUrines->setDeposit( ( true == isset( $row["deposit"] ) ) ? $row["deposit"] : 'NULL' );
			$objUrines->setReaction( ( true == isset( $row["reaction"] ) ) ? $row["reaction"] : 'NULL' );
			$objUrines->setAlbumin( ( true == isset( $row["albumin"] ) ) ? $row["albumin"] : 'NULL' );
			$objUrines->setSugar( ( true == isset( $row["sugar"] ) ) ? $row["sugar"] : 'NULL' );
			$objUrines->setScetene( ( true == isset( $row["scetene"] ) ) ? $row["scetene"] : 'NULL' );
			$objUrines->setDiaceticAcid( ( true == isset( $row["diacetic_acid"] ) ) ? $row["diacetic_acid"] : 'NULL' );
			$objUrines->setBileSacts( ( true == isset( $row["bile_sacts"] ) ) ? $row["bile_sacts"] : 'NULL' );
			$objUrines->setBileDigments( ( true == isset( $row["Bile_digments"] ) ) ? $row["Bile_digments"] : 'NULL' );
			$objUrines->setPusCells( ( true == isset( $row["pus_cells"] ) ) ? $row["pus_cells"] : 'NULL' );
			$objUrines->setPbc( ( true == isset( $row["pbc"] ) ) ? $row["pbc"] : 'NULL' );
			$objUrines->setCasts( ( true == isset( $row["casts"] ) ) ? $row["casts"] : 'NULL' );
			$objUrines->setCrystals( ( true == isset( $row["crystals"] ) ) ? $row["crystals"] : 'NULL' );
			$objUrines->setCells( ( true == isset( $row["cells"] ) ) ? $row["cells"] : 'NULL' );
			$objUrines->setMicroOrganisms( ( true == isset( $row["micro_organisms"] ) ) ? $row["micro_organisms"] : 'NULL' );
			$objUrines->setRemarks( ( true == isset( $row["remarks"] ) ) ? $row["remarks"] : 'NULL' );
			$objUrines->setDocumentAttachmentId( ( true == isset( $row["document_attachment_id"] ) ) ? $row["document_attachment_id"] : 'NULL' );
			$objUrines->setAttachmentPath( ( true == isset( $row["attachment_path"] ) ) ? $row["attachment_path"] : 'NULL' );
			$objUrines->setCreatedOn( ( true == isset( $row["created_on"] ) ) ? $row["created_on"] : 'NULL' );
			$objUrines->setCreatedBy( ( true == isset( $row["created_by"] ) ) ? $row["created_by"] : 'NULL' );
			$objUrines->setUpdatedOn( ( true == isset( $row["updated_on"] ) ) ? $row["updated_on"] : 'NULL' );
			$objUrines->setUpdatedBy( ( true == isset( $row["updated_by"] ) ) ? $row["updated_by"] : 'NULL' );
			array_push( $arrobjUrines, $objUrines);
		}
		return $arrobjUrines;
	}
	public function fetchAllUrinesByIds( $arrintIds ) {
		$result = $this->connection->RunQuery("SELECT * FROM URINES WHERE id IN ( implode( "," $arrintIds ) " );
		$arrobjUrines = array();
		while( $row = $result->fetch_array( MYSQLI_ASSOC ) ) {
			$objUrines->setId( ( true == isset( $row["id"] ) ) ? $row["id"] : 'NULL' );
			$objUrines->setPatientId( ( true == isset( $row["patient_id"] ) ) ? $row["patient_id"] : 'NULL' );
			$objUrines->setCasePaperId( ( true == isset( $row["case_paper_id"] ) ) ? $row["case_paper_id"] : 'NULL' );
			$objUrines->setDoctorId( ( true == isset( $row["doctor_id"] ) ) ? $row["doctor_id"] : 'NULL' );
			$objUrines->setDepartmentId( ( true == isset( $row["department_id"] ) ) ? $row["department_id"] : 'NULL' );
			$objUrines->setDiagnosisId( ( true == isset( $row["diagnosis_id"] ) ) ? $row["diagnosis_id"] : 'NULL' );
			$objUrines->setChargeId( ( true == isset( $row["charge_id"] ) ) ? $row["charge_id"] : 'NULL' );
			$objUrines->setColor( ( true == isset( $row["color"] ) ) ? $row["color"] : 'NULL' );
			$objUrines->setDeposit( ( true == isset( $row["deposit"] ) ) ? $row["deposit"] : 'NULL' );
			$objUrines->setReaction( ( true == isset( $row["reaction"] ) ) ? $row["reaction"] : 'NULL' );
			$objUrines->setAlbumin( ( true == isset( $row["albumin"] ) ) ? $row["albumin"] : 'NULL' );
			$objUrines->setSugar( ( true == isset( $row["sugar"] ) ) ? $row["sugar"] : 'NULL' );
			$objUrines->setScetene( ( true == isset( $row["scetene"] ) ) ? $row["scetene"] : 'NULL' );
			$objUrines->setDiaceticAcid( ( true == isset( $row["diacetic_acid"] ) ) ? $row["diacetic_acid"] : 'NULL' );
			$objUrines->setBileSacts( ( true == isset( $row["bile_sacts"] ) ) ? $row["bile_sacts"] : 'NULL' );
			$objUrines->setBileDigments( ( true == isset( $row["Bile_digments"] ) ) ? $row["Bile_digments"] : 'NULL' );
			$objUrines->setPusCells( ( true == isset( $row["pus_cells"] ) ) ? $row["pus_cells"] : 'NULL' );
			$objUrines->setPbc( ( true == isset( $row["pbc"] ) ) ? $row["pbc"] : 'NULL' );
			$objUrines->setCasts( ( true == isset( $row["casts"] ) ) ? $row["casts"] : 'NULL' );
			$objUrines->setCrystals( ( true == isset( $row["crystals"] ) ) ? $row["crystals"] : 'NULL' );
			$objUrines->setCells( ( true == isset( $row["cells"] ) ) ? $row["cells"] : 'NULL' );
			$objUrines->setMicroOrganisms( ( true == isset( $row["micro_organisms"] ) ) ? $row["micro_organisms"] : 'NULL' );
			$objUrines->setRemarks( ( true == isset( $row["remarks"] ) ) ? $row["remarks"] : 'NULL' );
			$objUrines->setDocumentAttachmentId( ( true == isset( $row["document_attachment_id"] ) ) ? $row["document_attachment_id"] : 'NULL' );
			$objUrines->setAttachmentPath( ( true == isset( $row["attachment_path"] ) ) ? $row["attachment_path"] : 'NULL' );
			$objUrines->setCreatedOn( ( true == isset( $row["created_on"] ) ) ? $row["created_on"] : 'NULL' );
			$objUrines->setCreatedBy( ( true == isset( $row["created_by"] ) ) ? $row["created_by"] : 'NULL' );
			$objUrines->setUpdatedOn( ( true == isset( $row["updated_on"] ) ) ? $row["updated_on"] : 'NULL' );
			$objUrines->setUpdatedBy( ( true == isset( $row["updated_by"] ) ) ? $row["updated_by"] : 'NULL' );
			array_push( $arrobjUrines, $objUrines );
		}
		return $arrobjUrines;
	}

	public function fetchUrinesById( $intId ) {
		$result = $this->connection->RunQuery( "SELECT * FROM URINES WHERE id = " . $intId );
			$objUrines = NULL;
		while($row = $result->fetch_array( MYSQLI_ASSOC ) ) {
			$objUrines = new BaseUrines();
			$objUrines->setId( ( true == isset( $row["id"] ) ) ? $row["id"] : 'NULL' );
			$objUrines->setPatientId( ( true == isset( $row["patient_id"] ) ) ? $row["patient_id"] : 'NULL' );
			$objUrines->setCasePaperId( ( true == isset( $row["case_paper_id"] ) ) ? $row["case_paper_id"] : 'NULL' );
			$objUrines->setDoctorId( ( true == isset( $row["doctor_id"] ) ) ? $row["doctor_id"] : 'NULL' );
			$objUrines->setDepartmentId( ( true == isset( $row["department_id"] ) ) ? $row["department_id"] : 'NULL' );
			$objUrines->setDiagnosisId( ( true == isset( $row["diagnosis_id"] ) ) ? $row["diagnosis_id"] : 'NULL' );
			$objUrines->setChargeId( ( true == isset( $row["charge_id"] ) ) ? $row["charge_id"] : 'NULL' );
			$objUrines->setColor( ( true == isset( $row["color"] ) ) ? $row["color"] : 'NULL' );
			$objUrines->setDeposit( ( true == isset( $row["deposit"] ) ) ? $row["deposit"] : 'NULL' );
			$objUrines->setReaction( ( true == isset( $row["reaction"] ) ) ? $row["reaction"] : 'NULL' );
			$objUrines->setAlbumin( ( true == isset( $row["albumin"] ) ) ? $row["albumin"] : 'NULL' );
			$objUrines->setSugar( ( true == isset( $row["sugar"] ) ) ? $row["sugar"] : 'NULL' );
			$objUrines->setScetene( ( true == isset( $row["scetene"] ) ) ? $row["scetene"] : 'NULL' );
			$objUrines->setDiaceticAcid( ( true == isset( $row["diacetic_acid"] ) ) ? $row["diacetic_acid"] : 'NULL' );
			$objUrines->setBileSacts( ( true == isset( $row["bile_sacts"] ) ) ? $row["bile_sacts"] : 'NULL' );
			$objUrines->setBileDigments( ( true == isset( $row["Bile_digments"] ) ) ? $row["Bile_digments"] : 'NULL' );
			$objUrines->setPusCells( ( true == isset( $row["pus_cells"] ) ) ? $row["pus_cells"] : 'NULL' );
			$objUrines->setPbc( ( true == isset( $row["pbc"] ) ) ? $row["pbc"] : 'NULL' );
			$objUrines->setCasts( ( true == isset( $row["casts"] ) ) ? $row["casts"] : 'NULL' );
			$objUrines->setCrystals( ( true == isset( $row["crystals"] ) ) ? $row["crystals"] : 'NULL' );
			$objUrines->setCells( ( true == isset( $row["cells"] ) ) ? $row["cells"] : 'NULL' );
			$objUrines->setMicroOrganisms( ( true == isset( $row["micro_organisms"] ) ) ? $row["micro_organisms"] : 'NULL' );
			$objUrines->setRemarks( ( true == isset( $row["remarks"] ) ) ? $row["remarks"] : 'NULL' );
			$objUrines->setDocumentAttachmentId( ( true == isset( $row["document_attachment_id"] ) ) ? $row["document_attachment_id"] : 'NULL' );
			$objUrines->setAttachmentPath( ( true == isset( $row["attachment_path"] ) ) ? $row["attachment_path"] : 'NULL' );
			$objUrines->setCreatedOn( ( true == isset( $row["created_on"] ) ) ? $row["created_on"] : 'NULL' );
			$objUrines->setCreatedBy( ( true == isset( $row["created_by"] ) ) ? $row["created_by"] : 'NULL' );
			$objUrines->setUpdatedOn( ( true == isset( $row["updated_on"] ) ) ? $row["updated_on"] : 'NULL' );
			$objUrines->setUpdatedBy( ( true == isset( $row["updated_by"] ) ) ? $row["updated_by"] : 'NULL' );
		}
		return $objUrines;
	}

	public function GetKeysOrderBy($column, $order){
		$keys = array(); $i = 0;
		$result = $this->connection->RunQuery("SELECT id from urines order by $column $order");
			while($row = $result->fetch_array(MYSQLI_ASSOC)){
				$keys[$i] = $row["id"];
				$i++;
			}
	return $keys;
	}

	public function endUrines(){
		$this->connection->CloseMysql();
	}

}